Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

interface-datastore

Package Overview
Dependencies
Maintainers
3
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

interface-datastore

datastore interface

  • 6.1.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
3
Created

What is interface-datastore?

The `interface-datastore` npm package provides a set of interfaces and utilities for creating and working with datastores. It is designed to be used as a base for implementing various types of datastores, such as in-memory, file-based, or networked datastores. The package is part of the IPFS (InterPlanetary File System) project and is used to standardize how data is stored and retrieved.

What are interface-datastore's main functionalities?

Basic Operations

This feature allows you to perform basic CRUD (Create, Read, Update, Delete) operations on a datastore. The example demonstrates how to put, get, and delete a value in an in-memory datastore.

const { MemoryDatastore } = require('interface-datastore');
const datastore = new MemoryDatastore();

// Put a value
await datastore.put(new Key('/example'), Buffer.from('Hello, world!'));

// Get a value
const value = await datastore.get(new Key('/example'));
console.log(value.toString()); // 'Hello, world!'

// Delete a value
await datastore.delete(new Key('/example'));

Querying

This feature allows you to query the datastore for entries that match certain criteria. The example demonstrates how to put multiple values and then query the datastore for entries with a specific prefix.

const { MemoryDatastore } = require('interface-datastore');
const datastore = new MemoryDatastore();

// Put some values
await datastore.put(new Key('/example/1'), Buffer.from('Value 1'));
await datastore.put(new Key('/example/2'), Buffer.from('Value 2'));
await datastore.put(new Key('/example/3'), Buffer.from('Value 3'));

// Query the datastore
const query = datastore.query({ prefix: '/example' });
for await (const { key, value } of query) {
  console.log(key.toString(), value.toString());
}

Batch Operations

This feature allows you to perform multiple operations in a single batch, which can be more efficient than performing them individually. The example demonstrates how to create a batch, add operations to it, and then commit the batch.

const { MemoryDatastore } = require('interface-datastore');
const datastore = new MemoryDatastore();

// Create a batch
const batch = datastore.batch();

// Add operations to the batch
batch.put(new Key('/example/1'), Buffer.from('Value 1'));
batch.put(new Key('/example/2'), Buffer.from('Value 2'));
batch.delete(new Key('/example/3'));

// Commit the batch
await batch.commit();

Other packages similar to interface-datastore

Keywords

FAQs

Package last updated on 22 Jun 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc